<!--
 * @Descripttion: 市场详情
 * @version: 
 * @Author: lehaixia
 * @Date: 2023-04-20 14:05:53
 * @LastEditors: lehaixia
 * @LastEditTime: 2023-06-30 09:03:08
-->
<template>
  <div class="m-detail">
    <detail-item label="市场名称" :value="detail.marketName" />
    <detail-item label="市场详细地址" :value="detail.address" />
    <detail-item label="市场类型" :value="getDictName('TOBE_MARKET_TYPE', detail.marketType)" />
    <detail-item label="市场属性" :value="getDictName('MARKET_NATURE', detail.marketNatrue)" />
    <!-- <detail-item label="数据来源" :value="getDictName('CTM_MARKET_DATA_FROM', detail.dataSource)" />
    <detail-item label="数据来源描述" :value="detail.dataSourceMsg" />
    <detail-item label="考核计划" :value="getDictName('CTM_APPRAISAL_PLAN', detail.appraisalPlan)" /> -->
    <detail-item label="任务日期" :value="parseTime(detail.createTime, '{y}年{m}月')" />
    <detail-item label="门店建设进度" :value="getDictName('BEFORE_CONST_SCHEDULE', detail.shopBuildStage)" />
    <detail-item label="市场跟进进度" :value="getDictName('CTM_MARKET_BUID_PROGRESS', detail.marketFollowUpStage)" />
    <detail-item label="办事处" :value="detail.agencyName" />
    <detail-item label="客户" :value="detail.customerName" />
    <detail-item label="门店" :value="detail.shopName" />
    <detail-item label="责任人" :value="detail.responsibleName" />
    <detail-item label="门店建设项目号" :value="detail.shopBuildNumber" />
    <detail-item label="说明" :value="detail.remark" />
    <detail-item label="结案日期" :value="parseTime(detail.settlementDate, '{y}年{m}月{d}日')" />
    <detail-item label="结案方式" :value="getDictName('CTM_CLOSED_TYPE', detail.settlementMethod)" />
  </div>
</template>

<script lang="ts">
  import DetailItem from '@/components/DetailItem/index.vue'
  import { detail } from '@/apis/storeUpgrade/index'
  import { useRoute } from 'vue-router'
  import { reactive, toRefs } from 'vue'
  import { getDictByPatchType } from '@/apis/dataDict'
  import { parseTime } from '@/utils'

  interface anyObjectModle {
    marketId: any
    detail: any
    dictData: any
  }
  export default {
    name: 'StoreUpgradeTaskMarketDetail',
    components: { DetailItem },
    setup() {
      const $route = useRoute()
      const datas = reactive<anyObjectModle>({
        marketId: $route.query.id || '',
        detail: {},
        dictData: {}
      })

      const getDictName = (dictType: string, code: any) => {
        if (!dictType || [undefined, null, ''].includes(code)) return ''
        let name = code
        const dictList = datas.dictData[dictType] || []
        if (dictList.length > 0) {
          const obj = dictList.find((v: any) => v.dictCode === `${code}`)
          name = obj?.dictName || code
        }
        return name
      }

      const getDetail = () => {
        const marketId = `${datas.marketId}`

        detail(marketId).then((res: any) => {
          datas.detail = res.data
        })
      }
      getDetail()

      // 获取数据字典
      const getDictData = async () => {
        const dictTypeCodes = [
          'CTM_MARKET_BUID_PROGRESS',
          'TOBE_MARKET_TYPE',
          'BEFORE_CONST_SCHEDULE',
          'CTM_CLOSED_TYPE',
          'MARKET_NATURE'
          // 'CTM_MARKET_DATA_FROM',
          // 'CTM_APPRAISAL_PLAN'
        ]
        datas.dictData = await getDictByPatchType({ dictTypeCodes })
      }

      getDictData()
      return {
        ...toRefs(datas),
        getDictName,
        parseTime
      }
    }
  }
</script>

<style lang="less" scoped>
  .m-detail {
    padding: 8px 0;
  }
</style>
